

<%@ page import="fi.hell.pollit.domain.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'poll.label', default: 'Poll')}" />
        <title><g:message code="default.create.label" args="[entityName]" /></title>
        <g:javascript library="jQuery" />
        <g:javascript library="poll" />
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
        </div>
        <div class="body">
            <h1><g:message code="default.create.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${pollInstance}">
            <div class="errors">
                <g:renderErrors bean="${pollInstance}" as="list" />
            </div>
            </g:hasErrors>
            <g:form action="save" >
                <div class="dialog">
                    <table>
                        <tbody id="pollFormTBody">
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="name"><g:message code="poll.name.label" default="Name" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'name', 'errors')}">
                                    <g:textField name="name" value="${pollInstance?.name}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="description"><g:message code="poll.description.label" default="Description" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'description', 'errors')}">
                                    <g:textField name="description" value="${pollInstance?.description}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="creator"><g:message code="poll.creator.label" default="Creator" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'creator', 'errors')}">
                                    ${User.getLoggedInUser()}
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="voteBeforeResults"><g:message code="poll.voteBeforeResults.label" default="Vote before view" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'voteBeforeResults', 'errors')}">
                                    <g:checkBox name="voteBeforeResults" value="${pollInstance?.voteBeforeResults}" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="publicPoll"><g:message code="poll.publicPoll.label" default="Public" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'publicPoll', 'errors')}">
                                    <g:checkBox name="publicPoll" value="${pollInstance?.publicPoll}" />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="multivote"><g:message code="poll.multivote.label" default="Multivote" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'multivote', 'errors')}">
                                    <g:checkBox name="multivote" value="${pollInstance?.multivote}" />
                                </td>
                            </tr>
                        
                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="validUntil"><g:message code="poll.validUntil.label" default="Valid Until" /></label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'validUntil', 'errors')}">
                                    <g:datePicker name="validUntil" precision="day" value="${pollInstance?.validUntil}"  />
                                </td>
                            </tr>

                            <tr class="prop">
                                <td valign="top" class="name">
                                    <label for="participants"><g:message code="poll.participants.label" default="Participants" /></label>
                                    <span class="helpText"><g:message code="poll.participants.info" default="No selection is meant for all" /></span>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'participants', 'errors')}">
                                    <select name="participants" multiple="multiple">
                                        <g:each in="${User.list()}">
                                            <option value="${it.id}" ${params.list("participants")?.contains(it.id.toString()) ? 'selected="selected"' : ''}>${it.fullName}</option>
                                        </g:each>
                                    </select>
                                </td>
                            </tr>

                            <g:each in="${pollInstance.options}" var="option" status="i">
                                <tr class="prop">
                                    <td valign="top" class="name">
                                        <label for="description"><g:message code="poll.option.label" default="Option" /> ${(i+1)}.</label>
                                    </td>
                                    <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'options', 'errors')}">
                                        <g:textField class="pollOptions" name="optionNames" value="${option}" />
                                    </td>
                                </tr>
                            </g:each>
                            <tr class="prop" id="pollOptionExtraRow">
                                <td valign="top" class="name">
                                    <label for="description"><g:message code="poll.option.label" default="Option" /> <span class="pollOptionNro">${(pollInstance.options?.size() ? pollInstance.options?.size()+1 : 1)}</span>.</label>
                                </td>
                                <td valign="top" class="value ${hasErrors(bean: pollInstance, field: 'options', 'errors')}">
                                    <g:textField class="pollOptions" name="optionNames" value="" />
                                </td>
                            </tr>


                        </tbody>
                    </table>
                </div>
                <div class="buttons">
                    <span class="button"><g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" /></span>
                </div>
            </g:form>
        </div>
    </body>
</html>
